//
//  ZYHomeMainVC.m
//  YiLin
//
//  Created by Zyark on 2018/5/29.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYHomeMainVC.h"
#import "ZYDeviceSwitchView.h"
#import "ZYDevice.h"
#import "ZYHouse.h"
#import "ZYHome.h"
#import "ZYCurve.h"
#import "ZYImageUtils.h"
#import "ZYDeviceItemView.h"
#import "ZYDeviceCommonItemView.h"
#import "ZYDeviceVSItemView.h"
#import "iCarousel.h"
#import "ZYWorkModeSelectView.h"
#import "ZYModeTypeModel.h"
#import "ZYCircleHanderView.h"
#import "ZYQuickSetupVC.h"
#import "ZYVSQuickSetupVC.h"
#import "ZYDeviceModifyVC.h"
#import "ZYDeviceAddVC.h"
#import "ZYDevicePolicyVC.h"
#import "ZYHistoricalDataVC.h"
#import "ZYDeviceViewModel.h"
#import "ZYSocketMessageUtils.h"
#import "ZYQuickSetupViewModel.h"
#import "ZYHouseViewModel.h"
#import "ZYCurveViewModel.h"
#import "RHSocketService.h"
#import "UIButton+ImageTitleSpacing.h"
#import "DeviceCommunicate.pbobjc.h"
#import "KxMenu.h"
#import "ZYTempratureModel.h"
#import "EBDropdownListView.h"
#import "NSTimer+SGLUnRetain.h"
#import "UINavigationController+FDFullscreenPopGesture.h"


#define CENTER_VIEW_WIDTH ZYSCREEN_W
#define CENTER_VIEW_TOP self.view.frame.size.height / 3

@interface ZYHomeMainVC ()<ZYDeviceSwitchViewDelegate,iCarouselDelegate,iCarouselDataSource,ZYDeviceItemViewDelegate,ZYWorkModeSelectViewDelegate>
@property(nonatomic,strong) UIImageView *bgImageView;

@property(nonatomic,strong) UIView *bgView;

/**
 空调
 */
@property(nonatomic,strong) UIButton *deviceACBtn;

/**
 地暖
 */
@property(nonatomic,strong) UIButton *deviceRFHBtn;

/**
 新风系统
 */
@property(nonatomic,strong) UIButton *deviceVSBtn;

/**智能*/
@property(nonatomic,strong) UIButton *deviceAIBtn;

/**
 设备开关View
 */
@property(nonatomic,strong) ZYDeviceSwitchView *deviceSwitchView;

/**
 添加设备按钮
 */
@property(nonatomic,strong) UIButton *addDeviceBtn;

/**
 设备类型
 */
@property(nonatomic,assign) ZYDeviceType deviceType;

@property(nonatomic,strong) ZYDeviceItemView *deviceItemView;

/**
 view轮播
 */
@property(nonatomic,strong) iCarousel *carousel;


/**
 空调
 */
@property(nonatomic,strong) NSMutableArray *acDeviceArray;

/**
 地暖
 */
@property(nonatomic,strong) NSMutableArray *rfhDeviceArray;

/**
 新风系统
 */
@property(nonatomic,strong) NSMutableArray *vsDeviceArray;


/**
 该住宅下的所有设备
 */
@property(nonatomic,strong) NSArray *deviceArray;

@property(nonatomic,strong) ZYDevice *currentDevice;

/**
 选中的索引
 */
@property(nonatomic,strong) NSMutableArray<NSNumber *> *indexArray;

@property(nonatomic,strong) ZYWorkModeSelectView *workModeSelectView;

/**
 右侧空调菜单组
 */
@property(nonatomic,strong) NSArray *rightACMenuItemArray;


/**
 右侧地暖菜单组
 */
@property(nonatomic,strong) NSArray *rightRFHMenuItemArray;

/**
 右侧新风系统菜单组
 */
@property(nonatomic,strong) NSArray *rightVSMenuItemArray;

/**
 左侧菜单组
 */
@property(nonatomic,strong) NSArray *leftMenuItemArray;

/**
 是否显示右边菜单
 */
@property(nonatomic,assign) BOOL isShowRightMenu;

/**
 左侧下拉选择
 */
@property(nonatomic,strong) EBDropdownListView *leftListView;

/**
 设备ViewModel
 */
@property(nonatomic,strong) ZYDeviceViewModel *deviceViewModel;

/**
 当前选中的房间类型
 */
@property(nonatomic,assign) ZYHomeRoomType roomType;

/**
 获取默认值
 */
@property(nonatomic,strong) ZYQuickSetupViewModel *quickSetupViewModel;

/**
 获取曲线值
 */
@property(nonatomic,strong) ZYCurveViewModel *viewModel;

/**
 新风模式默认值
 */
@property(nonatomic,strong) NSArray *vsDefaultValueArray;

/**
 空调地暖模式默认值
 */
@property(nonatomic,strong) NSArray *defaultValueArray;

/**住宅*/
@property(nonatomic,strong) ZYHouseViewModel *houseViewModel;

@property(nonatomic,strong) NSArray *homeArray;

/**
 当前住宅id
 */
@property(nonatomic,assign) NSInteger houseId;

/**
 当前住宅信息
 */
@property(nonatomic,strong) ZYHome *home;

/**当前曲线值*/
@property(nonatomic,strong) NSArray *currentArray;

/**定时器*/
@property(nonatomic, strong) NSTimer *timer;

@end

@implementation ZYHomeMainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setupRightButton];
    [self setupRightMenuItem];
//    [self setupLeftButton];
//    [self changeLanguage];
    _leftListView.hidden = NO;
    [self.houseViewModel.indexHouseCommand execute:nil];//获取住宅列表
    [self.deviceViewModel.deviceListCommand execute:nil];//获取该住宅设备列表
    if(!NULLString(_currentDevice.mac)){
        self.viewModel.macAddress = _currentDevice.mac;
        [self.viewModel.getCustomCurveCommand execute:nil];//获取自定义曲线
    }
    self.fd_interactivePopDisabled = YES;
    self.tabBarController.tabBar.hidden = NO;
//    if(_currentDevice.type != ZYDeviceTypeVentilationSystem){
    
//    }
}



- (void)dealloc {
    // 务必在当前线程调用invalidate方法，使得Runloop释放对timer的强引用(具体请参阅官方文档)
    [self.timer invalidate];
}

//初始化左侧导航栏
-(void)setupLeftButton{
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_HOME_MAIN_CONTROLLER_TITLE] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:20];
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = barButtonItem;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    _leftListView.hidden = YES;
    self.fd_interactivePopDisabled = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - init
-(void)setup{
    [self setupView];
    [self setupData];
    [self doDeviceSelect:_deviceACBtn];//默认选中空调
    [self bindView];
    [self setupTimer];
}

#pragma mark - 初始化定时器
-(void)setupTimer{
    @weakify(self)
    self.timer = [NSTimer sgl_scheduledTimerWithTimeInterval:60 repeats:YES block:^(NSTimer *timer) {
        @strongify(self)
        //更新温度
        if(!self.currentDevice.isTest && self.currentDevice.modeType && (self.currentDevice.type == ZYDeviceTypeAirConditioning || self.currentDevice.type == ZYDeviceTypeRadiantFloorHeating)){
            if(self.currentDevice.modeType == ZYDeviceModeCustom){
                //获取当前时间更新温度
                [self setupCustomModelTemplate];
            }
        }
    }];
}

-(void)setupCustomModelTemplate{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH"];
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    NSInteger currentHour = [currentTimeString integerValue];
    if(currentHour == 0){
        NSString *value = [self.currentArray lastObject];
        self.currentDevice.temperature = value;
        self.deviceItemView.device = self.currentDevice;
    }else{
        if(self.currentArray && [self.currentArray count] >(currentHour - 1)){
            NSString *value = [self.currentArray objectAtIndex:currentHour - 1];
            self.currentDevice.temperature = value;
            self.deviceItemView.device = self.currentDevice;
        }
    }
}

-(void)setupView{
//    _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W, ZYSCREEN_H * 0.63)];
//    [_bgImageView setImage:[UIImage imageNamed:@"ic_home_main_device_bg_ac"]];
//    [self.view addSubview:_bgImageView];
    _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W, ZYSCREEN_H * 0.63)];
    [_bgView.layer addSublayer:[ZYUtils setGradualChangingColor:_bgView fromHexColorStr:kMainColorStartColorHexString toHexColorStr:kMainColorEndColorHexString locations:@[@0.3, @1.0]]];
    [self.view addSubview:_bgView];
    _deviceSwitchView = [[ZYDeviceSwitchView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W - 30, DEVICE_SWITCH_VIEW_COMMON_HEIGHT)];
    _deviceSwitchView.delegate = self;
    [self.view addSubview:_deviceSwitchView];
    _deviceSwitchView.centerX = self.view.centerX;
    _deviceSwitchView.top = _bgView.bottom + 10;
    
    _deviceACBtn = [self setupDeviceTypeButton];
    _deviceVSBtn = [self setupDeviceTypeButton];
    _deviceRFHBtn = [self setupDeviceTypeButton];
    _deviceAIBtn = [self setupDeviceTypeButton];
    _deviceACBtn.tag = ZYDeviceTypeAirConditioning;
    _deviceVSBtn.tag = ZYDeviceTypeVentilationSystem;
    _deviceRFHBtn.tag = ZYDeviceTypeRadiantFloorHeating;
    _deviceAIBtn.tag = ZYDeviceTypeAI;
    
    _deviceACBtn.top = GetRectNavAndStatusHight + 20;
    _deviceACBtn.left = 15;
    
    
    _deviceRFHBtn.centerY = _deviceACBtn.centerY;
    _deviceRFHBtn.left = _deviceACBtn.right;
    
    _deviceVSBtn.centerY = _deviceRFHBtn.centerY;
    _deviceVSBtn.left = _deviceRFHBtn.right;
    
    _deviceAIBtn.centerY = _deviceVSBtn.centerY;
    _deviceAIBtn.left = _deviceVSBtn.right;
    
    
    [self setupCarousel];
    
//    [self setupLeftListView];
    
    [self setupAddButton];
    
    [self setupWorkModeSelectView];
    
    [self setupLeftListView];
}

//绑定view
-(void)bindView{
    //设备socket地址 获取后重新连接socket
    @weakify(self)
    [[[self.deviceViewModel.deviceSocketCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        [self reconnectWithIp:x macAddress:self.deviceViewModel.mac isDisconnect:NO];//重新连接socket
    }];
    [self.deviceViewModel.deviceSocketCommand.errors subscribeNext:^(id x) {
        @strongify(self);
        [ZYBasicHelper handleErrorMessaeWithError:x message:[NSErrorHelper handleErrorMessage:x] controller:self];
    }];
    
    //获取该住宅设备列表
    [[[self.deviceViewModel.deviceListCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        self.deviceArray = x;
        [self setupData];

    }];
    [self.deviceViewModel.deviceListCommand.errors subscribeNext:^(id x) {
        @strongify(self);
        if([[NSErrorHelper handleErrorMessage:x] isEqualToString:LOGIN_FAILURE]){
            //登录失效
            [ZYBasicHelper handleErrorMessaeWithError:x message:nil controller:self];
        }
    }];
    //获取模式值
    [[[self.quickSetupViewModel.modeValueCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        [self setupViewModelValue:x];
    }];
    //空调地暖模式默认值
    [[[self.quickSetupViewModel.modeDefaultCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        NSDictionary *dict = x;
        ZYModeTypeModel *esModel = [[ZYModeTypeModel alloc] init];
        esModel.modeType = ZYDeviceModeEnergySaving;
        esModel.value = [dict objectForKey:[NSString stringWithFormat:@"%ld",(long)ZYDeviceModeEnergySaving]];
        
        ZYModeTypeModel *comModel = [[ZYModeTypeModel alloc] init];
        comModel.modeType = ZYDeviceModeComfortable;
        comModel.value = [dict objectForKey:[NSString stringWithFormat:@"%ld",(long)ZYDeviceModeComfortable]];
        
        ZYModeTypeModel *customModel = [[ZYModeTypeModel alloc] init];
        customModel.modeType = ZYDeviceModeCustom;
        customModel.value = [dict objectForKey:[NSString stringWithFormat:@"%ld",(long)ZYDeviceModeCustom]];
        
        self.defaultValueArray = @[esModel,comModel,customModel];
        [self setupDefaultValue];
    }];
    //新风模式默认值
    [[[self.quickSetupViewModel.vsFilterCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        NSDictionary *dict = x;
        self.vsDefaultValueArray = [dict objectForKey:@"mode"];
        [self setupDefaultValue];
    }];
    [self.quickSetupViewModel.modeValueCommand.errors subscribeNext:^(id x) {
        @strongify(self);
        [ZYBasicHelper handleErrorMessaeWithError:x message:[NSErrorHelper handleErrorMessage:x] controller:self];
    }];
    
    //删除设备
    [[[self.deviceViewModel.deleteCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        [[ToastHelper sharedToastHelper] toastSuccess:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_DELETE_DEVICE_SUCCESS]];
        [self.deviceViewModel.deviceListCommand execute:nil];//获取住宅设备列表
    }];
    [self.deviceViewModel.deleteCommand.errors subscribeNext:^(id x) {
        @strongify(self);
        [ZYBasicHelper handleErrorMessaeWithError:x message:[NSErrorHelper handleErrorMessage:x] controller:self];
    }];
    
    //住宅列表
    [[[self.houseViewModel.indexHouseCommand executionSignals] switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        self.homeArray = x;
        NSMutableArray *dataSource = [NSMutableArray arrayWithCapacity:[x count]];
        for (ZYHouse *house in x) {
            EBDropdownListItem *item = [[EBDropdownListItem alloc] initWithItem:[NSString stringWithFormat:@"%ld",(long)house.houseId] itemName:house.name];
            [dataSource addObject:item];
        }
        self.leftListView.dataSource = dataSource;
        NSString *houseId = [ZYConfig houseId];
        BOOL isAtHome = NO;
        if(NULLString(houseId) || [houseId isEqualToString:@"0"]){
            ZYHouse *house = [self.homeArray firstObject];
            [ZYConfig setHouseId:[NSString stringWithFormat:@"%ld",(long)house.houseId]];
            self.houseId = house.houseId;
            isAtHome = house.userIn;
        }else{
            NSInteger index = 0;
            for (ZYHouse *house in self.homeArray) {
                if(house.houseId == [houseId integerValue]){
                    isAtHome = house.userIn;
                    break;
                }
                index ++;
            }
            self.leftListView.selectedIndex = index;
            self.houseId = [houseId unsignedIntegerValue];
        }
        [self.deviceViewModel.deviceListCommand execute:nil];//获取住宅设备列表
        //        self.homeViewModel.houseId = self.houseId;
        //        [self.homeViewModel.dataCommand execute:nil];//获取顶部数据
        [self countWidth:self.leftListView];//重新计算宽度
        [ZYConfig setIsAtHome:isAtHome];
    }];
    
    [self.houseViewModel.indexHouseCommand.errors subscribeNext:^(id x) {
        @strongify(self);
        NSString *houseId = [ZYConfig houseId];
        BOOL isAtHome = NO;
        if(NULLString(houseId) || [houseId isEqualToString:@"0"]){//当获取的住宅列表为空时
            self.homeArray = [NSArray array];
            self.leftListView.dataSource = [NSArray array];
            [self countWidth:self.leftListView];//重新计算宽度
            self.deviceArray = [NSMutableArray array];
            self.home = nil;
            [ZYConfig setIsAtHome:isAtHome];
        }
        [ZYBasicHelper handleErrorMessaeWithError:x message:[NSErrorHelper handleErrorMessage:x] controller:self];
    }];
    
    //-(void)bindGetCustomCurve{
    //获取自定义曲线值
    [[self.viewModel.getCustomCurveCommand.executionSignals switchToLatest] subscribeNext:^(id x) {
        @strongify(self);
        ZYCurve *curve = x;
        NSString *value = curve.value;
        NSArray *valueArray = [value componentsSeparatedByString:@","];;
        self.currentArray = valueArray;
    }];
}

/**
 设置设备默认的温度或风速
 */
-(void)setupDefaultValue{
    NSArray *array;
    self.quickSetupViewModel.mac = _currentDevice.mac;
    if(_currentDevice.type == ZYDeviceTypeVentilationSystem){
        array = self.vsDefaultValueArray;
        if(!array || [array count] == 0){
            [self.quickSetupViewModel.vsFilterCommand execute:nil];
            return;
        }
    }else{
        array = self.defaultValueArray;
        if(!array || [array count] == 0){
            [self.quickSetupViewModel.modeDefaultCommand execute:nil];
            return;
        }
    }
    //获取模式值
    [self.quickSetupViewModel.modeValueCommand execute:[NSNumber numberWithUnsignedInteger:_currentDevice.serverDeviceType]];
}

//初始化视图
-(void)setupViewModelValue:(NSArray *)modelArray{
    for (ZYModeTypeModel *model in modelArray) {
        if(model.modeType != self.currentDevice.modeType){
            continue;
        }
        [self setupSocketWithModel:model];
        return;
    }
    if(_currentDevice.type == ZYDeviceTypeVentilationSystem){
        modelArray = self.vsDefaultValueArray;
    }else{
        modelArray = self.defaultValueArray;
    }
    for (ZYModeTypeModel *model in modelArray) {
        if(model.modeType != self.currentDevice.modeType){
            continue;
        }
        [self setupSocketWithModel:model];
        return;
    }
}

-(void)setupSocketWithModel:(ZYModeTypeModel *)model{
    NSDictionary *dict;
    if(self.deviceType == ZYDeviceTypeVentilationSystem){//新风系统
        NSUInteger type ;
        if(model.modeType == ZYVSModeTypeAuto){
            type = model.autoWindSpeedType;
        }else{
            type = model.speedType;
        }
        if(_currentDevice.isNewVS){//新风风速 1-10级
            ZYWindSpeedIn100Type windSpeedIn100Type;
            switch (model.speedType) {
                case ZYWindSpeedTypeHeight:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeHeight;
                    break;
                case ZYWindSpeedTypeMiddle:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeMiddle;
                    break;
                case ZYWindSpeedTypeLow:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeLow;
                    break;
                default:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeMiddle;
                    break;
            }
            type = windSpeedIn100Type;
        }
        //改变当前风速
        if(model.modeType == ZYVSModeTypeAuto){//新风自动模式
            self.currentDevice.windSpeedType = model.autoWindSpeedType;
            //socket控制设备
            
            NSString *sleepTime = [NSString stringWithFormat:@"%@:%@/%@:%@",model.startHour,model.startMinute,model.endHour,model.endMinute];
            if(_currentDevice.isNewVS){
                dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:ZYVSModeTypeAuto],@"sleepTime":sleepTime,@"cleanTime":[NSNumber numberWithInteger:model.autoMinute],@"windSpeedIn100":[NSNumber numberWithUnsignedInteger:type]};
            }else{
                dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:ZYVSModeTypeAuto],@"sleepTime":sleepTime,@"cleanTime":[NSNumber numberWithInteger:model.autoMinute],@"windSpeed":[NSNumber numberWithUnsignedInteger:type]};
            }
        }else{
            if(model.modeType == ZYVSModeTypeMixedWind){
                if(_currentDevice.isNewVS){
                    dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:ZYVSModeTypeMixedWind],@"windSpeedIn100":[NSNumber numberWithFloat:type],@"valvaAngleInMixWind":[NSNumber numberWithInt:model.proportion]};
                }else{
                    dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:ZYVSModeTypeMixedWind],@"windSpeed":[NSNumber numberWithFloat:type],@"valvaAngleInMixWind":[NSNumber numberWithInt:model.proportion]};
                }
            }else{
                if(_currentDevice.isNewVS){
                    dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:model.modeType],@"windSpeedIn100":[NSNumber numberWithFloat:type]};
                }else{
                    dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:model.modeType],@"windSpeed":[NSNumber numberWithFloat:type]};
                }
            }
            self.currentDevice.windSpeedType = model.speedType;
        }
        self.deviceSwitchView.device = self.currentDevice;
    }else{//改变当前设置温度
        self.currentDevice.temperature = model.value;
        self.deviceItemView.device = self.currentDevice;
        if(_currentDevice.modeType == ZYDeviceModeCustom){//自定义模式不需要传模式
            dict = @{@"lockStatus":@0,@"powerStatus":@1,@"setTemperatureC2":model.value};
        }else{
            dict = @{@"lockStatus":@0,@"pannelModel":[NSNumber numberWithUnsignedInteger:_currentDevice.modeType],@"powerStatus":@1,@"setTemperatureC2":model.value};
        }
    }
    if(_currentDevice.isOpen){
        [ZYSocketMessageUtils setDeviceWithMac:_currentDevice.mac andParams:dict];
    }
}

-(void)setupData{
    _indexArray = [NSMutableArray arrayWithObjects:@0,@0,@0, nil];
    _acDeviceArray = [NSMutableArray array];
    _vsDeviceArray = [NSMutableArray array];
    _rfhDeviceArray = [NSMutableArray array];
    for (ZYDevice *device in self.deviceArray) {
        switch (device.type) {
            case ZYDeviceTypeAirConditioning:
                [_acDeviceArray addObject:device];
                break;
            case ZYDeviceTypeVentilationSystem:
                [_vsDeviceArray addObject:device];
                break;
            case ZYDeviceTypeRadiantFloorHeating:
                [_rfhDeviceArray addObject:device];
                break;
            default:
                break;
        }
    }
    if([_acDeviceArray count] == 0){
        [_acDeviceArray addObject:[self setupDefaultDevice:ZYDeviceTypeAirConditioning]];
    }
    if([_vsDeviceArray count] == 0){
        [_vsDeviceArray addObject:[self setupDefaultDevice:ZYDeviceTypeVentilationSystem]];
    }
    if([_rfhDeviceArray count] == 0){
        [_rfhDeviceArray addObject:[self setupDefaultDevice:ZYDeviceTypeRadiantFloorHeating]];
    }
    [_carousel setCurrentItemIndex:0];
    [_carousel reloadData];
//    [self setupLeftListView];
    [self setupCurrentDevice];
}

-(void)setupAddButton{
    _addDeviceBtn = [[UIButton alloc] init];
    _addDeviceBtn.size = CGSizeMake(120, 40);
    [_addDeviceBtn setBackgroundImage:[ZYImageUtils imageWithColor:kMainColor rect:_addDeviceBtn.frame] forState:UIControlStateHighlighted];
    [_addDeviceBtn setBackgroundImage:[ZYImageUtils imageWithColor:[UIColor whiteColor] rect:_addDeviceBtn.frame] forState:UIControlStateNormal];
    [_addDeviceBtn setTitleColor:kMainColor forState:UIControlStateNormal];
    [_addDeviceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    _addDeviceBtn.layer.cornerRadius = 20;
    _addDeviceBtn.layer.masksToBounds = YES;
    _addDeviceBtn.layer.borderWidth = 2;
    _addDeviceBtn.layer.borderColor = RGBA(248, 248, 248, 1).CGColor;
    [_addDeviceBtn addTarget:self action:@selector(doAddDevice:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_addDeviceBtn];
    _addDeviceBtn.centerX = self.view.centerX;
    _addDeviceBtn.bottom = self.tabBarController.tabBar.top - 5;
    
    UIPanGestureRecognizer *panRcognize=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
    [panRcognize setMinimumNumberOfTouches:1];
    [panRcognize setEnabled:YES];
    [panRcognize delaysTouchesEnded];
    [panRcognize cancelsTouchesInView];
    [_addDeviceBtn addGestureRecognizer:panRcognize];//添加手势
//    CGFloat width = ZYSCREEN_W * 0.65;
//    _deviceItemView = [[ZYDeviceItemView alloc] initWithFrame:CGRectMake(0, 0, width, 0.8 * width)];
//    [self.view addSubview:_deviceItemView];
//    _deviceItemView.centerX = self.view.centerX;
//    _deviceItemView.top = _deviceACBtn.bottom + width * 0.17;
//    _deviceItemView.device = [self setupDefaultDevice];
    
}

-(void)setupCarousel{
    CGFloat height = _bgView.height - _deviceACBtn.bottom - 10;
    NSLog(@"setupCarousel:%.0f , %.0f  , %.0f",_deviceSwitchView.top,_deviceACBtn.bottom,height);
//    CGFloat top = (_deviceSwitchView.top - _deviceACBtn.bottom  - width) /2;
    _carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, _deviceACBtn.bottom + 10, ZYSCREEN_W, height)];
    [self.view addSubview:_carousel];
    _carousel.centerX = self.view.centerX;
//    _carousel.top = _deviceACBtn.bottom + top;
    _carousel.centerY = (_deviceSwitchView.top - _deviceACBtn.bottom) / 2 + _deviceACBtn.bottom;
    _carousel.delegate = self;
    _carousel.dataSource = self;
    _carousel.backgroundColor = [UIColor clearColor];
    _carousel.bounces = YES;
    _carousel.pagingEnabled = YES;
    _carousel.type = iCarouselTypeLinear;
}

-(UIButton *)setupDeviceTypeButton{
    CGFloat height = 35;
    CGFloat width = (ZYSCREEN_W - 30 ) / 4;
    UIButton *button = [[UIButton alloc] init];
    button.size = CGSizeMake(width, height);
    [button setBackgroundImage:[ZYImageUtils imageWithColor:[UIColor whiteColor] rect:button.bounds] forState:UIControlStateSelected];
    [button setBackgroundImage:[ZYImageUtils imageWithColor:[UIColor clearColor] rect:button.bounds] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:kMainColor forState:UIControlStateSelected];
    button.layer.cornerRadius = 8;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(doDeviceSelect:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    return button;
}

-(void)setupWorkModeSelectView{
    _workModeSelectView = [[ZYWorkModeSelectView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W, ZYSCREEN_H)];
    _workModeSelectView.delegate = self;
//    [self.view addSubview:_workModeSelectView];
}

//切换房间
//-(void)setupLeftListView{
//
//    _leftListView = [[EBDropdownListView alloc] init];
//    _leftListView.size = CGSizeMake(90, 35);
//    _leftListView.backgroundColor = [UIColor clearColor];
//    _leftListView.font = [UIFont systemFontOfSize:20];
//    _leftListView.textColor = kLabelColor;
//    _leftListView.selectTextColor = [UIColor whiteColor];
//    _leftListView.arrowImgName = @"ic_home_main_select";
//    @weakify(self);
//    [_leftListView setDropdownListViewSelectedBlock:^(EBDropdownListView *dropdownListView) {
//        @strongify(self);
//        //房间类型改变
//        EBDropdownListItem *item = dropdownListView.selectedItem;
//
//        NSArray *array = [item.itemId componentsSeparatedByString:@"_"];
//        NSInteger type = [[array objectAtIndex:0] integerValue];
//        NSInteger index = [[array objectAtIndex:1] integerValue];
//        [self.indexArray setObject:[NSNumber numberWithInteger:index] atIndexedSubscript:type];
////        [self setupCurrentDevice];
//        switch (type) {
//            case ZYDeviceTypeAirConditioning:
//
//                [self doDeviceSelect:self.deviceACBtn];
//                break;
//            case ZYDeviceTypeVentilationSystem:
//                [self doDeviceSelect:self.deviceVSBtn];
//                break;
//            case ZYDeviceTypeRadiantFloorHeating:
//                [self doDeviceSelect:self.deviceRFHBtn];
//                break;
//
//        }
//    }];
////    _leftListView.dataSource = [self setupLeftArray];
////    [self countWidth:_leftListView];
//
//}

//切换住宅
-(void)setupLeftListView{
    _leftListView = [[EBDropdownListView alloc] init];
    _leftListView.size = CGSizeMake(90, 35);
    _leftListView.backgroundColor = [UIColor clearColor];
    _leftListView.font = [UIFont systemFontOfSize:20];
    _leftListView.textColor = kLabelColor;
    _leftListView.selectTextColor = [UIColor whiteColor];
    _leftListView.arrowImgName = @"ic_home_main_select";
    @weakify(self);
    [_leftListView setDropdownListViewSelectedBlock:^(EBDropdownListView *dropdownListView) {
        @strongify(self);
        //选中一个住宅
        NSInteger index = dropdownListView.selectedIndex;
        ZYHouse *house = [self.homeArray objectAtIndex:index];
        if(house){
            [ZYConfig setHouseId:[NSString stringWithFormat:@"%ld",(long)house.houseId]];
            self.houseId = house.houseId;
            [ZYConfig setIsAtHome:house.userIn];
            [self.deviceViewModel.deviceListCommand execute:nil];//获取住宅设备列表
        }
    }];
    [self countWidth:_leftListView];
}


#pragma mark - 获取设备当前索引
-(NSInteger)getDeviceIndex:(ZYDevice *)device{
    switch (device.type) {
        case ZYDeviceTypeAirConditioning:
            return [_acDeviceArray indexOfObject:device];
            break;
        case ZYDeviceTypeVentilationSystem:
            return [_vsDeviceArray indexOfObject:device];
            break;
        case ZYDeviceTypeRadiantFloorHeating:
            return [_rfhDeviceArray indexOfObject:device];
            break;
        case ZYDeviceTypeAI:
            break;
        default:
            break;
    }
    return 0;
}

//房间列表
//-(NSArray *)setupLeftArray{
//    ZYChangeLanguage *language = [ZYChangeLanguage sharedZYChangeLanguage];
//    NSArray *array = @[[language getStringByKey:LC_INDEX_MAIN_LIVING_ROOM_LABEL],
//                       [language getStringByKey:LC_INDEX_MAIN_BEDROOM_LABEL],
//                       [language getStringByKey:LC_INDEX_MAIN_CHILDREN_ROOM_LABEL]];
//    NSInteger count = 0;
//    NSMutableArray *dataSource = [NSMutableArray arrayWithCapacity:[array count]];
//    for (NSString *title in array) {
//        ZYHomeRoomType roomType = ZYHomeRoomTypeChildrenRoom;
//        switch (count) {
//            case 0:
//                roomType = ZYHomeRoomTypeLivingRoom;
//                break;
//            case 1:
//                roomType = ZYHomeRoomTypeBedroom;
//                break;
//            case 2:
//                roomType = ZYHomeRoomTypeChildrenRoom;
//                break;
//        }
//        EBDropdownListItem *item = [[EBDropdownListItem alloc] initWithItem:[NSString stringWithFormat:@"%ld",roomType] itemName:title];
//        [dataSource addObject:item];
//        count ++;
//    }
//    return dataSource;
//}
#pragma mark - 获取所有设备标题
//-(NSArray *)setupLeftArray{
//    NSInteger count = 0;
//    NSMutableArray *dataSource = [NSMutableArray array];
//    for (ZYDevice *device in _acDeviceArray) {
//        EBDropdownListItem *item = [[EBDropdownListItem alloc] initWithItem:[NSString stringWithFormat:@"%ld_%ld",(long)device.type,count] itemName:device.name];
//        [dataSource addObject:item];
//        count ++;
//    }
//    count =0;
//    for (ZYDevice *device in _rfhDeviceArray) {
//        EBDropdownListItem *item = [[EBDropdownListItem alloc] initWithItem:[NSString stringWithFormat:@"%ld_%ld",device.type,count] itemName:device.name];
//        [dataSource addObject:item];
//        count ++;
//    }
//    count =0;
//    for (ZYDevice *device in _vsDeviceArray) {
//        EBDropdownListItem *item = [[EBDropdownListItem alloc] initWithItem:[NSString stringWithFormat:@"%ld_%ld",device.type,count] itemName:device.name];
//        [dataSource addObject:item];
//        count ++;
//    }
//    return dataSource;
//}

#pragma mark - 计算控件宽度
-(void)countWidth:(EBDropdownListView *)dropdownListView{
    NSString *longestItem = @"";
    for (EBDropdownListItem *item in dropdownListView.dataSource) {
        if ([item.itemName length] > [longestItem length]) {
            longestItem = item.itemName;
        }
    }
    NSDictionary *attributes = @{NSFontAttributeName:dropdownListView.font,};
    CGSize textSize = [longestItem boundingRectWithSize:CGSizeMake(ZYSCREEN_W * 0.75, dropdownListView.height)
                                                options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    CGFloat width = textSize.width + 40;
    if([dropdownListView.dataSource count] == 0){
        width = 20;
    }
    if(width > ZYSCREEN_W / 2){
        width = ZYSCREEN_W / 2;
    }
    _leftListView.width = width;
    dropdownListView.width = width;
    if(ZYiOS_11_OR_LATER){
        [_leftListView removeFromSuperview];
        self.navigationItem.hidesBackButton = YES;
        [self.navigationController.navigationBar addSubview:_leftListView];
        _leftListView.left = 15;
    }else{
        UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_leftListView];
        self.navigationItem.leftBarButtonItems = @[barButtonItem];
    }
}

//-(void)countWidth:(EBDropdownListView *)dropdownListView{
//    NSString *longestItem = @"";
//    for (EBDropdownListItem *item in dropdownListView.dataSource) {
//        if ([item.itemName length] > [longestItem length]) {
//            longestItem = item.itemName;
//        }
//    }
//    NSDictionary *attributes = @{NSFontAttributeName:dropdownListView.font,};
//    CGSize textSize = [longestItem boundingRectWithSize:CGSizeMake(ZYSCREEN_W * 0.75, dropdownListView.height)
//                                                options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
//    CGFloat width = textSize.width + 40;
//    dropdownListView.width = width;
//    _leftListView.width = width;
//    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_leftListView];
//    self.navigationItem.leftBarButtonItem = barButtonItem;
//}
//初始化右侧导航栏
-(void)setupRightButton{
    UIButton *button = [[UIButton alloc] init];
    button.frame = CGRectMake(0, 0, 40, 25);
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitle:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_HOME_DEVICE_EDIT_BTN_TITLE] forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont systemFontOfSize:16]];
    self.navigationItem.rightBarButtonItem = barButtonItem;
    [button addTarget:self action:@selector(showRightMenu:) forControlEvents:UIControlEventTouchUpInside];

    //    [barButtonItem setTarget:self];
    //    barButtonItem.action = @selector(popController);
    
}


/**
 初始化标题
 */
-(void)changeLanguage{
    [super changeLanguage];
    ZYChangeLanguage *language = [ZYChangeLanguage sharedZYChangeLanguage];
    [_deviceSwitchView setupTitle];
    NSString *addBtnTitle = [NSString stringWithFormat:@"+ %@",[language getStringByKey:LC_HOME_EDIT_DEVICE_ADD_DEVICE]];
    NSString *deviceACTitle = [language getStringByKey:LC_DEVICE_TYPE_AIR_CONDITIONING];
    NSString *deviceRFHTitle = [language getStringByKey:LC_DEVICE_TYPE_RADIANT_FLOOR_HEATING];
    NSString *deviceVCTitle = [language getStringByKey:LC_DEVICE_TYPE_VENTILATION_SYSTEM];
    NSString *deviceAITitle = [language getStringByKey:LC_DEVICE_TYPE_AI];
    [_addDeviceBtn setTitle:addBtnTitle forState:UIControlStateNormal];
    [_addDeviceBtn setTitle:addBtnTitle forState:UIControlStateSelected];
    
    [_deviceACBtn setTitle:deviceACTitle forState:UIControlStateNormal];
    [_deviceACBtn setTitle:deviceACTitle forState:UIControlStateSelected];
    
    [_deviceRFHBtn setTitle:deviceRFHTitle forState:UIControlStateNormal];
    [_deviceRFHBtn setTitle:deviceRFHTitle forState:UIControlStateSelected];
    
    [_deviceVSBtn setTitle:deviceVCTitle forState:UIControlStateNormal];
    [_deviceVSBtn setTitle:deviceVCTitle forState:UIControlStateSelected];
    
    [_deviceAIBtn setTitle:deviceAITitle forState:UIControlStateNormal];
    [_deviceAIBtn setTitle:deviceAITitle forState:UIControlStateSelected];
    
    [_workModeSelectView setupTitle];
    
    //更新设备详细信息视图
    _deviceItemView.device = _currentDevice;
    [_carousel reloadData];
    
//    _leftListView.dataSource = [self setupLeftArray];
//    [self countWidth:_leftListView];
}

-(ZYDevice *)setupDefaultDevice:(NSUInteger )deviceType{
    ZYDevice *device = [[ZYDevice alloc] init];
    device.type = deviceType;
    device.name = @"-";
    device.windSpeedType = ZYWindSpeedTypeMiddle;
    device.modeType = ZYDeviceModeCustom;
    device.temperature = @"10";
    device.pmExponent = @"-";
    device.pmQuality = @"-";
    device.tvoc = @"-";
    device.humidity = @"0";
    device.roomTemperature = @"-";
    device.isTest = YES;
    device.isLock = YES;
    device.isOpen = NO;
    return device;
}

-(void)setupCurrentDevice{
    NSNumber *index = [_indexArray objectAtIndex:_deviceType];
    ZYDevice *device = nil;
    NSUInteger currentIndex = 0;
    switch (_deviceType) {
        case ZYDeviceTypeAirConditioning:
            if([_acDeviceArray count] == 1){
                _carousel.scrollEnabled = NO;
            }else{
                _carousel.scrollEnabled = YES;
            }
            currentIndex = [index integerValue];
            device = [_acDeviceArray objectAtIndex:[index integerValue]];
            break;
        case ZYDeviceTypeVentilationSystem:
            if([_vsDeviceArray count] == 1){
                _carousel.scrollEnabled = NO;
            }else{
                _carousel.scrollEnabled = YES;
            }
            device = [_vsDeviceArray objectAtIndex:[index integerValue]];
            currentIndex = [_acDeviceArray count] + [_rfhDeviceArray count] + + [index integerValue];
            break;
        case ZYDeviceTypeRadiantFloorHeating:
            if([_rfhDeviceArray count] == 1){
                _carousel.scrollEnabled = NO;
            }else{
                _carousel.scrollEnabled = YES;
            }
            currentIndex = [_acDeviceArray count] + [index integerValue];
            device = [_rfhDeviceArray objectAtIndex:[index integerValue]];
            break;
    }
//    [_leftListView setSelectedIndex:currentIndex];
    if(device.isTest){
        _currentDevice = device;
        if([[RHSocketService sharedInstance] isRunning]){
            [[RHSocketService sharedInstance] stopService];
        }
        return;
    }
    _currentDevice = device;
    if([_currentDevice.mac isEqualToString:device.mac] && [[RHSocketService sharedInstance] isRunning]){
        //更新视图
//        _deviceItemView.device = _currentDevice;
//        _deviceSwitchView.device = _currentDevice;
        [self getDeviceData];//重新获取
        return;
    }
    if([[RHSocketService sharedInstance] isRunning]){
        [[RHSocketService sharedInstance] stopService];
    }
    if(!NULLString(_currentDevice.mac)){
        self.viewModel.macAddress = _currentDevice.mac;
        [self.viewModel.getCustomCurveCommand execute:nil];//获取自定义曲线
    }
    self.deviceViewModel.mac = _currentDevice.mac;
    [self.deviceViewModel.deviceSocketCommand execute:nil];//获取设备socket地址
}

-(ZYDevice *)setupDevice:(NSInteger)index{

    ZYDevice *device = nil;
    switch (_deviceType) {
        case ZYDeviceTypeAirConditioning:
            if([_acDeviceArray count] == 1){
                _carousel.scrollEnabled = NO;
            }else{
                _carousel.scrollEnabled = YES;
            }
            device = [_acDeviceArray objectAtIndex:index];
            break;
        case ZYDeviceTypeVentilationSystem:
            if([_vsDeviceArray count] == 1){
                _carousel.scrollEnabled = NO;
            }else{
                _carousel.scrollEnabled = YES;
            }
            device = [_vsDeviceArray objectAtIndex:index];
            break;
        case ZYDeviceTypeRadiantFloorHeating:
            if([_rfhDeviceArray count] == 1){
                _carousel.scrollEnabled = NO;
            }else{
                _carousel.scrollEnabled = YES;
            }
            device = [_rfhDeviceArray objectAtIndex:index];
            break;
    }
    return device;
}


-(void)setupRightMenuItem{
    ZYChangeLanguage *language = [[ZYChangeLanguage alloc] init];
    _rightRFHMenuItemArray =
    @[
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_TEMPERATURE_CONTROL_STRATEGY]
                     image:[UIImage imageNamed:@"ic_home_edit_temperature_control"]
                    target:self
                    action:@selector(gotoTemperatureControlStrategy)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_QUICK_SETUP]
                     image:[UIImage imageNamed:@"ic_home_edit_quick_setup"]
                    target:self
                    action:@selector(gotoQuickSetup)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_EQUIPMENT_EDITING]
                     image:[UIImage imageNamed:@"ic_home_edit_equipment_editing"]
                    target:self
                    action:@selector(gotoEquipmentEditing)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_DELETE_DEVICE]
                     image:[UIImage imageNamed:@"ic_home_edit_delete"]
                    target:self
                    action:@selector(deleteDevice)],
      ];
    _rightACMenuItemArray =
    @[
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_TEMPERATURE_CONTROL_STRATEGY]
                     image:[UIImage imageNamed:@"ic_home_edit_temperature_control"]
                    target:self
                    action:@selector(gotoTemperatureControlStrategy)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_QUICK_SETUP]
                     image:[UIImage imageNamed:@"ic_home_edit_quick_setup"]
                    target:self
                    action:@selector(gotoQuickSetup)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_WORK_MODE]
                     image:[UIImage imageNamed:@"ic_home_edit_work_mode"]
                    target:self
                    action:@selector(selectWorkMode)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_EQUIPMENT_EDITING]
                     image:[UIImage imageNamed:@"ic_home_edit_equipment_editing"]
                    target:self
                    action:@selector(gotoEquipmentEditing)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_DELETE_DEVICE]
                     image:[UIImage imageNamed:@"ic_home_edit_delete"]
                    target:self
                    action:@selector(deleteDevice)],
      ];
    _rightVSMenuItemArray =
    @[
//      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_HISTORICAL_DATA]
//                     image:[UIImage imageNamed:@"ic_home_edit_historical_data"]
//                    target:self
//                    action:@selector(gotoHistoricalData)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_QUICK_SETUP]
                     image:[UIImage imageNamed:@"ic_home_edit_quick_setup"]
                    target:self
                    action:@selector(gotoQuickSetup)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_EQUIPMENT_EDITING]
                     image:[UIImage imageNamed:@"ic_home_edit_equipment_editing"]
                    target:self
                    action:@selector(gotoEquipmentEditing)],
      [KxMenuItem menuItem:[language getStringByKey:LC_HOME_EDIT_DEVICE_DELETE_DEVICE]
                     image:[UIImage imageNamed:@"ic_home_edit_delete"]
                    target:self
                    action:@selector(deleteDevice)],
      ];
}

#pragma mark iCarousel datasource delegate
-(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
    switch (_deviceType) {
        case ZYDeviceTypeAirConditioning:
            return _acDeviceArray.count;
        case ZYDeviceTypeVentilationSystem:
            return _vsDeviceArray.count;
        case ZYDeviceTypeRadiantFloorHeating:
            return _rfhDeviceArray.count;
            break;
        case ZYDeviceTypeAI:
            break;
    }
    return 0;
}

-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
    if(!view){
        CGFloat height = carousel.height;

        ZYDevice *device;
        ZYDeviceItemView *deviceItemView;
        if(_currentDevice.type == ZYDeviceTypeVentilationSystem){
            deviceItemView = [[ZYDeviceVSItemView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W,  height)];
        }else{
            deviceItemView = [[ZYDeviceCommonItemView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W,  height)];
        }
        
//        [self.view addSubview:deviceItemView];
//        deviceItemView.centerX = self.view.centerX;
//        deviceItemView.top = _deviceACBtn.bottom + 10;
//        [_deviceItemView setSidesViewHidden:NO];
        
        deviceItemView.device = device;
        view = deviceItemView;
        deviceItemView.delegate = self;
        if(carousel.currentItemIndex == index){
            _deviceItemView = deviceItemView;
        }
    }
    return view;
}

- (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel{
    [_deviceItemView setScrollStatus:NO];
    [(ZYDeviceItemView *)carousel.currentItemView setScrollStatus:NO];
    _deviceItemView.device = _currentDevice;
}

- (void)carouselDidScroll:(iCarousel *)carousel{
    [(ZYDeviceItemView *)carousel.currentItemView setScrollStatus:YES];
    [_deviceItemView setScrollStatus:YES];
}

- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel{
    NSLog(@"___3 %lu",(long)carousel.currentItemIndex);
    _deviceItemView = (ZYDeviceItemView *)carousel.currentItemView;
    [_indexArray setObject:[NSNumber numberWithInteger:carousel.currentItemIndex] atIndexedSubscript:_deviceType];
    [self setupCurrentDevice];
}


#pragma mark - ZYDeviceItemViewDelegate
//模式改变
-(void)deviceItemView:(ZYDeviceItemView *)deviceItemView setModeType:(NSUInteger)modeType device:(ZYDevice *)device{
    if(device.isTest){
        return;
    }
//    NSDictionary *dict;
//    if(device.type == ZYDeviceTypeVentilationSystem){
//        dict = @{@"windPannelModel":[NSNumber numberWithUnsignedInteger:modeType]};
//    }else{
//        dict = @{@"pannelModel":[NSNumber numberWithUnsignedInteger:modeType]};
//    }
    if(device.type == ZYDeviceTypeAirConditioning || device.type == ZYDeviceTypeRadiantFloorHeating){
        if(modeType == ZYDeviceModeCustom){
            //设置自定义温度
            NSDictionary *dict = @{@"controlFlag":@5,@"curveId":@0};
            [ZYSocketMessageUtils setDeviceWithMac:device.mac andParams:dict andCmd:5];
            [self setupCustomModelTemplate];//设置自定义温度
            return;
        }
    }
    [self setupDefaultValue];//获取模式值
//    [ZYSocketMessageUtils setDeviceWithMac:device.mac andParams:dict];
}

-(void)deviceItemView:(ZYDeviceItemView *)deviceItemView isChangeTemperature:(BOOL)isChange{
    [_carousel setScrollEnabled:!isChange];
    switch (_deviceType) {
        case ZYDeviceTypeAirConditioning:
            _carousel.scrollEnabled = [_acDeviceArray count] != 1;
            break;
        case ZYDeviceTypeVentilationSystem:
            _carousel.scrollEnabled = [_vsDeviceArray count] != 1;
            break;
        case ZYDeviceTypeRadiantFloorHeating:
            _carousel.scrollEnabled = [_rfhDeviceArray count] != 1;
            break;
    }
}

//温度改变
-(void)deviceItemView:(ZYDeviceItemView *)deviceItemView changeTemperature:(int)temperature device:(ZYDevice *)device{
    if(device.isTest){
        return;
    }
    //修改socket 和http的模式温度
    //设置当前模式为手动模式
    _currentDevice.modeType = ZYDeviceModeManual;
    self.deviceItemView.device = _currentDevice;
    self.quickSetupViewModel.mac = _currentDevice.mac;
    [self.quickSetupViewModel setModeValueWithDeviceType:_currentDevice.serverDeviceType andModel:_currentDevice.modeType andParams:[NSString stringWithFormat:@"%d",temperature]];
    NSDictionary *dict = @{@"lockStatus":@0,@"pannelModel":[NSNumber numberWithUnsignedInteger:_currentDevice.modeType],@"powerStatus":@1,@"setTemperatureC2":[NSNumber numberWithInt:temperature]};
    [ZYSocketMessageUtils setDeviceWithMac:_currentDevice.mac andParams:dict];
}

#pragma mark - ZYDeviceSwitchViewDelegate

//是否锁定
-(void)deviceSwitchView:(ZYDeviceSwitchView *)deviceSwitchView setDeviceLock:(BOOL)isLock device:(ZYDevice *)device switchBtn:(UISwitch *)switchBtn{
    [(ZYDeviceItemView *)_carousel.currentItemView setIsLock:isLock];
    if(device.isTest){
        return;
    }
    NSDictionary *dict = @{@"lockStatus":isLock ? @1 : @0};
    [ZYSocketMessageUtils setDeviceStatusWithMac:device.mac andParams:dict];
}

//是否开启
-(void)deviceSwitchView:(ZYDeviceSwitchView *)deviceSwitchView setDeviceOpen:(BOOL)isOpen device:(ZYDevice *)device switchBtn:(UISwitch *)switchBtn{
    _currentDevice.isOpen = isOpen;
    [(ZYDeviceItemView *)_carousel.currentItemView setIsOpen:isOpen];
    if(device.isTest){
        return;
    }
    NSDictionary *dict = @{@"powerStatus":isOpen ? @1 : @0};
    [ZYSocketMessageUtils setDeviceStatusWithMac:device.mac andParams:dict];
}

//选择风速
-(void)deviceSwitchView:(ZYDeviceSwitchView *)deviceSwitchView setWindSpeedType:(ZYWindSpeedType)type device:(ZYDevice *)device button:(UIButton *)button{
    if(device.isTest){
        return;
    }
    NSDictionary *dict;
    if(device.type == ZYDeviceTypeVentilationSystem){
        //改为手动模式
        _currentDevice.vsModeType = ZYVSModeTypManual;
        _deviceItemView.device = _currentDevice;
        if(device.isNewVS){
            ZYWindSpeedIn100Type windSpeedIn100Type;
            switch (type) {
                case ZYWindSpeedTypeHeight:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeHeight;
                    break;
                case ZYWindSpeedTypeMiddle:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeMiddle;
                    break;
                case ZYWindSpeedTypeLow:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeLow;
                    break;
                default:
                    windSpeedIn100Type = ZYWindSpeedIn100TypeMiddle;
                    break;
            }
            dict = @{@"windSpeedIn100":[NSNumber numberWithUnsignedInteger:windSpeedIn100Type],@"windPannelModel":[NSNumber numberWithUnsignedInteger:ZYVSModeTypManual]};
            //设置http 风速
            self.quickSetupViewModel.mac = _currentDevice.mac;
            [self.quickSetupViewModel setModeValueWithDeviceType:_currentDevice.serverDeviceType andModel:ZYVSModeTypManual andParams:[NSString stringWithFormat:@"%ld",(long)type]];
        }else{
            dict = @{@"windSpeed":[NSNumber numberWithUnsignedInteger:type],@"windPannelModel":[NSNumber numberWithUnsignedInteger:ZYVSModeTypManual]};
            //设置http 风速
            self.quickSetupViewModel.mac = _currentDevice.mac;
            [self.quickSetupViewModel setModeValueWithDeviceType:_currentDevice.serverDeviceType andModel:ZYVSModeTypManual andParams:[NSString stringWithFormat:@"%ld",(long)type]];
        }
    }else{
        dict = @{@"windSpeed":[NSNumber numberWithUnsignedInteger:type]};
    }
    [ZYSocketMessageUtils setDeviceWithMac:device.mac andParams:dict];
    _currentDevice.windSpeedType = type;
}

#pragma mark -ZYWorkModeSelectViewDelegate

-(void)workModeSelectView:(ZYWorkModeSelectView *)workModeSelectView setModeType:(NSUInteger)modeType{
    if(_currentDevice.isTest){
        return;
    }
    NSDictionary *dict = @{@"workModel":[NSNumber numberWithUnsignedInteger:modeType]};
    [ZYSocketMessageUtils setDeviceWithMac:_currentDevice.mac andParams:dict];
}

#pragma mark -Event

//添加按钮 手势拖动
- (void)handlePanGesture:(UIPanGestureRecognizer *)recognizer
{
    //移动状态
    UIGestureRecognizerState recState =  recognizer.state;
    
    switch (recState) {
        case UIGestureRecognizerStateBegan:
            
            break;
        case UIGestureRecognizerStateChanged:
        {
            CGPoint translation = [recognizer translationInView:self.navigationController.view];
            recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
        }
            break;
        case UIGestureRecognizerStateEnded:
        {
            CGPoint stopPoint = CGPointMake(0, ZYSCREEN_H / 2.0);
            CGFloat top = SafeAreaTopHeight + 5 + _addDeviceBtn.height / 2;
            CGFloat bottom = self.tabBarController.tabBar.top - 5 - _addDeviceBtn.height / 2;
            if (recognizer.view.center.x < ZYSCREEN_W / 2.0) {
                if (recognizer.view.center.y <= ZYSCREEN_H/2.0) {
                    //左上
                    if (recognizer.view.center.x  >= recognizer.view.center.y) {
                        stopPoint = CGPointMake(recognizer.view.center.x, top);
                    }else{
                        stopPoint = CGPointMake(_addDeviceBtn.width/2.0, recognizer.view.center.y);
                    }
                }else{
                    //左下
                    if (recognizer.view.center.x  >= ZYSCREEN_H - recognizer.view.center.y) {
                        stopPoint = CGPointMake(recognizer.view.center.x, bottom);
                    }else{
                        stopPoint = CGPointMake(_addDeviceBtn.width/2.0, recognizer.view.center.y);
                        //                        stopPoint = CGPointMake(recognizer.view.center.x, ZYSCREEN_H - _addDeviceBtn.width/2.0);
                    }
                }
            }else{
                if (recognizer.view.center.y <= ZYSCREEN_H/2.0) {
                    //右上
                    if (ZYSCREEN_W - recognizer.view.center.x  >= recognizer.view.center.y) {
                        stopPoint = CGPointMake(recognizer.view.center.x, top);
                    }else{
                        stopPoint = CGPointMake(ZYSCREEN_W - _addDeviceBtn.width/2.0, recognizer.view.center.y);
                    }
                }else{
                    //右下
                    if (ZYSCREEN_W - recognizer.view.center.x  >= ZYSCREEN_H - recognizer.view.center.y) {
                        stopPoint = CGPointMake(recognizer.view.center.x, bottom);
                    }else{
                        stopPoint = CGPointMake(ZYSCREEN_W - _addDeviceBtn.width/2.0,recognizer.view.center.y);
                    }
                }
            }
            
            //如果按钮超出屏幕边缘
            if (stopPoint.y + _addDeviceBtn.height  >= self.tabBarController.tabBar.top - 5) {
                stopPoint = CGPointMake(stopPoint.x, bottom);
                NSLog(@"超出屏幕下方了！！"); //这里注意iphoneX的适配。。X的SCREEN高度算法有变化。
            }
            if (stopPoint.x - _addDeviceBtn.width/2.0 <= 0) {
                stopPoint = CGPointMake(_addDeviceBtn.width/2.0, stopPoint.y);
            }
            if (stopPoint.x + _addDeviceBtn.width/2.0 >= ZYSCREEN_W) {
                stopPoint = CGPointMake(ZYSCREEN_W - _addDeviceBtn.width/2.0, stopPoint.y);
            }
            if (stopPoint.y - _addDeviceBtn.height/2.0  <= SafeAreaTopHeight) {
                stopPoint = CGPointMake(stopPoint.x,  top);
            }
            
            [UIView animateWithDuration:0.5 animations:^{
                recognizer.view.center = stopPoint;
            }];
        }
            break;
            
        default:
            break;
    }
    
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}

/**
 添加设备
 @param button 按钮
 */
-(void)doAddDevice:(UIButton *)button{
    if(NULLString([ZYConfig houseId])){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_ADD_HOUSE_PROMPT]];
        return;
    }
    ZYDeviceAddVC *vc = [[ZYDeviceAddVC alloc] init];
    vc.deviceType = _currentDevice.type;
    [self.navigationController pushViewController:vc animated:YES];
}

/**
 设备选择
 @param button 按钮
 */
-(void)doDeviceSelect:(UIButton *)button{
    if(button.isSelected){
        return;
    }
    if(button.tag == ZYDeviceTypeAI){
        [[ToastHelper sharedToastHelper] toast:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_DEVELOPING_PROMPT]];
        return;
    }
    _deviceType = button.tag;
    [self setupCurrentDevice];
    _workModeSelectView.workModeType = _currentDevice.workModeType;
    _deviceItemView.device = _currentDevice;
    _deviceSwitchView.device = _currentDevice;
    _deviceACBtn.selected = NO;
    _deviceRFHBtn.selected = NO;
    _deviceVSBtn.selected = NO;
    _deviceAIBtn.selected = NO;
//    switch (_deviceType) {
//        case ZYDeviceTypeAirConditioning:
//            [_bgImageView setImage:[UIImage imageNamed:@"ic_home_main_device_bg_ac"]];
//            break;
//        case ZYDeviceTypeVentilationSystem:
//            [_bgImageView setImage:[UIImage imageNamed:@"ic_home_main_device_bg_vs"]];
//            break;
//        case ZYDeviceTypeRadiantFloorHeating:
//            [_bgImageView setImage:[UIImage imageNamed:@"ic_home_main_device_bg_rfh"]];
//            break;
//
//        default:
//            break;
//    }
    [_carousel reloadData];
    button.selected = YES;
}


/**
 弹出或隐藏工作模式选择
 */
-(void)showAndHiddenWorkModeSelectView{
    [_workModeSelectView showOrHidden];
}


/**
 显示右边菜单
 @param button 按钮
 */
-(void)showRightMenu:(UIButton *)button{
    _isShowRightMenu = !_isShowRightMenu;
    if(_isShowRightMenu){
        [KxMenu setTintColor:[UIColor whiteColor]];
        [KxMenu setTitleFont:[UIFont systemFontOfSize:14]];
        //    CGRect rect =  CGRectMake(0, 0, 0, 0);
        NSArray *menuArray;
        if(_deviceType == ZYDeviceTypeAirConditioning){
            menuArray = _rightACMenuItemArray;
        }else if(_deviceType == ZYDeviceTypeRadiantFloorHeating){
            menuArray = _rightRFHMenuItemArray;
        }else{
            menuArray = _rightVSMenuItemArray;
        }
        [KxMenu showMenuInView:self.view fromRect:[self.navigationController.view convertRect:button.frame fromView:button.superview] menuItems:menuArray withOptions:[self setupMenuConfig]];
//        [KxMenu showMenuInView:self.view
//                      fromRect:[self.navigationController.view convertRect:button.frame fromView:button.superview]
//                     menuItems:menuArray];
    }else{
        [KxMenu dismissMenu];
    }
}


/**
 配置菜单参数

 @return OptionalConfiguration
 */
-(OptionalConfiguration)setupMenuConfig{
    Color textColor;
    textColor.R = 102/255.0;
    textColor.G = 102/255.0;
    textColor.B = 102/255.0;
    Color menuBackgroundColor;
    menuBackgroundColor.R = 1;
    menuBackgroundColor.G = 1;
    menuBackgroundColor.B = 1;
    OptionalConfiguration config;
    config.arrowSize = 0;//指示箭头大小
    config.marginXSpacing = 5;  //MenuItem左右边距
    config.marginYSpacing = 8;  //MenuItem上下边距
    config.intervalSpacing = 10;//MenuItemImage与MenuItemTitle的间距
    config.menuCornerRadius = 5;//菜单圆角半径
    config.maskToBackground = NO;//是否添加覆盖在原View上的半透明遮罩
    config.hasSeperatorLine = NO;
    config.textColor = textColor; //menuItem字体颜色
    config.menuBackgroundColor = menuBackgroundColor;
    config.hasSeperatorLine = NO;
    return config;
}

/**
 温控策略
 */
-(void)gotoTemperatureControlStrategy{
    _isShowRightMenu = NO;
    if(_currentDevice.isTest){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_SELECT_DEVICE_PROMPT]];
        return;
    }
    ZYDevicePolicyVC *vc = [[ZYDevicePolicyVC alloc] init];
    vc.device = _currentDevice;
    [self.navigationController pushViewController:vc animated:YES];
}

/**
 快捷设置
 */
-(void)gotoQuickSetup{
    _isShowRightMenu = NO;
    if(_currentDevice.isTest){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_SELECT_DEVICE_PROMPT]];
        return;
    }
    if(_deviceType == ZYDeviceTypeVentilationSystem){
        ZYVSQuickSetupVC *vc = [[ZYVSQuickSetupVC alloc] init];
        vc.device = _currentDevice;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        ZYQuickSetupVC *vc = [[ZYQuickSetupVC alloc] init];
        vc.device = _currentDevice;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

/**
 工作模式
 */
-(void)selectWorkMode{
    _isShowRightMenu = NO;
    if(_currentDevice.isTest){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_SELECT_DEVICE_PROMPT]];
        return;
    }
    [_workModeSelectView showOrHidden];
}


/**
 设备编辑
 */
-(void)gotoEquipmentEditing{
    _isShowRightMenu = NO;
    if(_currentDevice.isTest){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_SELECT_DEVICE_PROMPT]];
        return;
    }
    ZYDeviceModifyVC *vc = [[ZYDeviceModifyVC alloc] init];
    vc.device = _currentDevice;
    vc.mac = _currentDevice.mac;
    vc.isModify = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


/**
 历史数据
 */
-(void)gotoHistoricalData{
    _isShowRightMenu = NO;
    if(_currentDevice.isTest){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_SELECT_DEVICE_PROMPT]];
        return;
    }
    ZYHistoricalDataVC *vc = [[ZYHistoricalDataVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

/**
 删除设备
 */
-(void)deleteDevice{
    _isShowRightMenu = NO;
    if(_currentDevice.isTest){
        [[ToastHelper sharedToastHelper] toastError:[[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_SELECT_DEVICE_PROMPT]];
        return;
    }
    ZYChangeLanguage *language = [ZYChangeLanguage sharedZYChangeLanguage];
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[language getStringByKey:LC_DELETE_DEVICE_HINT] message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    @weakify(self)
    [alertController addAction:[UIAlertAction actionWithTitle:[language getStringByKey:LC_ALERT_CONTER_BTN_CONFIRM] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        @strongify(self);
        self.deviceViewModel.mac = _currentDevice.mac;
        [self.deviceViewModel.deleteCommand execute:nil];
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:[language getStringByKey:LC_ALERT_CONTER_BTN_CANCEL] style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        return;
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark - Getter

-(ZYHouseViewModel *)houseViewModel{
    if(!_houseViewModel){
        _houseViewModel = [[ZYHouseViewModel alloc] init];
    }
    return _houseViewModel;
}


-(ZYDeviceViewModel *)deviceViewModel{
    if(!_deviceViewModel){
        _deviceViewModel = [[ZYDeviceViewModel alloc] init];
    }
    return _deviceViewModel;
}

-(ZYQuickSetupViewModel *)quickSetupViewModel{
    if(!_quickSetupViewModel){
        _quickSetupViewModel = [[ZYQuickSetupViewModel alloc] init];
    }
    return _quickSetupViewModel;
}

#pragma mark - socket

-(void)getDeviceData{
    device_communicate *message = [[device_communicate alloc] init];
    RHSocketPacketRequest *req = [[RHSocketPacketRequest alloc] init];
    message.module = 100;
    message.cmd = 1;
    message.sid = [ZYConfig loginToken];
    message.userId = [ZYConfig userId];
    message.macAddress = _currentDevice.mac;
//    NSSet *data = [NSSet setWithArray:@[@"powerStatus",@"lockStatus",@"pannelModel"
//                                        ,@"loadStatus",@"roomTemperatureC2",@"environmentAlarm1"
//                                        ,@"deviceAlarm1",@"controlFlag",@"workModel",@"windSpeed",@"windPannelModel"]];
    message.jsonStr = @"";
    NSLog(@"json:%@",message.jsonStr);
    req.object = [message data];
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSocketPacketRequest object:req];
}

-(void)receiveMsgData:(device_communicate *)data{
    if(!NULLString(data.jsonStr)){
        NSData *jsonData = [data.jsonStr dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData: jsonData options:NSJSONReadingAllowFragments error:nil];
        NSString *code = [dict objectForKey:@"code"];
        NSLog(@"module:%d",data.module);
        NSLog(@"cmd:%d",data.cmd);
        if([code integerValue] == 200){
            if(![[dict objectForKey:@"result"] isKindOfClass:[NSDictionary class]]){
                return;
            }
            ZYDevice *device = [ZYDevice modelWithJSON:[dict objectForKey:@"result"]];
            NSDictionary *result = [dict objectForKey:@"result"];
            NSDictionary *roomTemperatureC2 = [result objectForKey:@"roomTemperatureC2"];
            NSDictionary *setTemperatureC2 = [result objectForKey:@"setTemperatureC2"];
            if(roomTemperatureC2){
                _currentDevice.isConnect = YES;
                _currentDevice.isLock = device.isLock;
                _currentDevice.isOpen = device.isOpen;
                _currentDevice.curveType = device.curveType;
                _currentDevice.roomTemperature = device.roomTemperature;
                _currentDevice.workModeType = device.workModeType;
                _currentDevice.vsModeType = device.vsModeType;
                _currentDevice.windSpeedType = device.windSpeedType;
                _currentDevice.pmExponent = device.pmExponent;
                _currentDevice.outPmExponent = device.outPmExponent;
                _currentDevice.humidity = device.humidity;
                _currentDevice.outHumidity = device.outHumidity;
                _currentDevice.outTemperature = device.outTemperature;
                _currentDevice.formaldehyde = device.formaldehyde;
                _currentDevice.tvoc = device.tvoc;
                _currentDevice.carbonDioxide = device.carbonDioxide;
                _currentDevice.roomTemperature = [NSString stringWithFormat:@"%@",[roomTemperatureC2 objectForKey:@"value"]];
                _currentDevice.windSpeedIn100 = device.windSpeedIn100;
                if([[result allKeys] containsObject:@"windSpeedIn100"]){
                    _currentDevice.isNewVS = YES;
                }else{
                    _currentDevice.isNewVS = NO;
                }
                
                //更新视图
                CGFloat temperature = [[setTemperatureC2 objectForKey:@"value"] doubleValue];
                _currentDevice.temperature = [NSString stringWithFormat:@"%.0f",roundf(temperature)];
                _workModeSelectView.workModeType = _currentDevice.workModeType;
                _deviceItemView.device = _currentDevice;
                _deviceSwitchView.device = _currentDevice;
                self.quickSetupViewModel.mac = _currentDevice.mac;
                [self.quickSetupViewModel.modeValueCommand execute:[NSNumber numberWithUnsignedInteger:_currentDevice.serverDeviceType]];//获取风速
            }
        }
    }
}


-(ZYCurveViewModel *)viewModel{
    if(!_viewModel){
        _viewModel = [[ZYCurveViewModel alloc] init];
        _viewModel.macAddress = _currentDevice.mac;
    }
    return _viewModel;
}


-(void)connectSocketSuccess:(NSNotification *)notif{
    [self getDeviceData];//获取设备信息
}
@end
